﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Entity;
using System.Runtime.Serialization;
using System.IO;
using System.Drawing;
using System.Drawing.Imaging;
using TriviaModel;

namespace TriviaDal
{
    /// <summary>
    /// Question class that the app familiar with
    /// </summary>
    [DataContract]
    public class QuestionCalss
    {
        [DataMember]
        public int Id { get; set; }
        [DataMember]
        public string QuestionImage { get; set; }
        [DataMember]
        public int? TypeId { get; set; }
        [DataMember]
        public int? DificultyId { get; set; }
        [DataMember]
        public string Clue { get; set; }
        [DataMember]
        public string QuestionString { get; set; }
        [DataMember]
        public List<AnswerCalss> Answers { get; set; }

    }
    /// <summary>
    /// Answer class that the app familiar with
    /// </summary>
    [DataContract]
    public class AnswerCalss
    {
        [DataMember]
        public int Id { get; set; }
        [DataMember]
        public string AnswerString { get; set; }
        [DataMember]
        public int QuestionId { get; set; }
        [DataMember]
        public bool? IsRightAnswer { get; set; }

    }
    /// <summary>
    /// user class that the app familiar with
    /// </summary>
    [DataContract]
    public class UserClass
    {
        [DataMember]
        public string UserName { get; set; }
        [DataMember]
        public int? score { get; set; }

    }


    /// <summary>
    /// has static methods that transforms enttity to objects
    /// </summary>
    public class Converter
    {
        public static  Question ToEntityQuestionConverter(QuestionCalss triviaq)
        {
            return new Question()
            {
                QuestionImage  = triviaq.QuestionImage,
                QuestionString = triviaq.QuestionString,
                TypeId = triviaq.TypeId,
                Clue = triviaq.Clue,
                DificultyId = triviaq.DificultyId,   
            };
        }

        public static QuestionCalss ToClassQuestionConverter(Question triviaq)
        {
            return new QuestionCalss()
            {
                Id = triviaq.ID,
                Clue = triviaq.Clue,
                QuestionString = triviaq.QuestionString,
                DificultyId = triviaq.DificultyId,
                QuestionImage = triviaq.QuestionImage,
                TypeId = triviaq.TypeId,
            };
        }

        public static Answer ToEntityAnswerConverter(AnswerCalss triviaa)
        {
            return new Answer()
            {
                Id = triviaa.Id,
                AnswerString = triviaa.AnswerString,
                QuestionId = triviaa.QuestionId,
            };
        }
        public static AnswerCalss ToClassAnswerConverter(Answer triviaa)
        {
            return new AnswerCalss()
            {
                Id = triviaa.Id,
                AnswerString = triviaa.AnswerString,
                QuestionId = triviaa.QuestionId,
            };
        }

        public static UserClass ToClassUserConverter(User user)
        {
            return new UserClass()
            {
                UserName = user.UserName,
                score = user.Score
            };
        }

        //public byte[] imageToByteArray(Image imageIn)
        //{
        //    MemoryStream ms = new MemoryStream();
        //    imageIn.Save(ms, ImageFormat.Gif);
        //    return ms.ToArray();
        //}

        //public Image byteArrayToImage(byte[] byteArrayIn)
        //{
        //    MemoryStream ms = new MemoryStream(byteArrayIn);
        //    Image returnImage = Image.FromStream(ms);
        //    return returnImage;

        //}


    }
}
